package fivestar.ui.user;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import org.netbeans.validation.api.ValidatorUtils;
import org.netbeans.validation.api.builtin.stringvalidation.StringValidators;
import org.netbeans.validation.api.ui.ValidationGroup;
import org.netbeans.validation.api.ui.swing.ValidationPanel;

public class Register extends javax.swing.JDialog implements ActionListener,
		ItemListener, KeyListener {

	private static final long serialVersionUID = -4800414210063077974L;

	private JLabel lblUserName, lblPassword, lblRole;
	JLabel lblUser;
	JLabel lblNewLabel;
	private JTextField txtUserName;
	private JPasswordField txtPassword;
	private JButton btnAdd, btnCancel;
	JButton btnNewButton;
	@SuppressWarnings("rawtypes")
	private JComboBox cboRole;
	private JPanel pnlUser,pnlTitle, pnlLocation, pnlOption;
	JSeparator separator;
	String ruta = "No tiene";
	String country = "";
 
	ValidationPanel pnlValidation;
	ValidationGroup group;

	public Register(Frame parent, boolean modal) {
		super(parent, modal);
		setResizable(false);
		initComponents();
		this.setLocationRelativeTo(null);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void initComponents() {
		try {
			
			getContentPane().setLayout(null);

			pnlUser = new JPanel();
			pnlUser.setBounds(290, 5, 334, 261);
			getContentPane().add(pnlUser);
			pnlUser.setLayout(null);

			pnlValidation = new ValidationPanel();
			pnlValidation.setBounds(0, 0, 383, 290);
			pnlValidation.setInnerComponent(pnlUser);
			getContentPane().add(pnlValidation);
			group = pnlValidation.getValidationGroup();
			

			pnlTitle = new JPanel();
			pnlTitle.setBounds(10, 0, 352, 67);
			pnlTitle.setForeground(new Color(0, 0, 0));
			pnlUser.add(pnlTitle);
			pnlTitle.setLayout(null);

			separator = new JSeparator();
			separator.setBounds(5, 36, 337, 2);
			pnlTitle.add(separator);

			lblUser = new JLabel("User");
			lblUser.setHorizontalAlignment(SwingConstants.LEFT);
			lblUser.setVerticalAlignment(SwingConstants.TOP);
			lblUser.setFont(new Font("Tahoma", Font.PLAIN, 30));
			lblUser.setBounds(10, 0, 233, 38);
			pnlTitle.add(lblUser);

			lblNewLabel = new JLabel("Register");
			lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
			lblNewLabel.setVerticalAlignment(SwingConstants.BOTTOM);
			lblNewLabel.setForeground(new Color(0, 0, 0));
			lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 20));
			lblNewLabel.setBounds(10, 36, 233, 27);
			pnlTitle.add(lblNewLabel);
 
			// Tabla Location
			pnlLocation = new JPanel();
			pnlLocation.setBounds(10, 75, 352, 125);
			pnlUser.add(pnlLocation);
			/*pnlLocation.setBorder(BorderFactory.createTitledBorder(null,
					"", TitledBorder.DEFAULT_JUSTIFICATION,
					TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 0, 10)));*/
			pnlLocation.setLayout(null);

			lblUserName = new JLabel("User Name :");
			lblUserName.setHorizontalAlignment(SwingConstants.TRAILING);
			lblUserName.setBounds(10, 23, 110, 26);
			lblUserName.setFont(new Font("Tahoma", Font.PLAIN, 11));
			pnlLocation.add(lblUserName);

			txtUserName = new JTextField();
			txtUserName.setBounds(125, 23, 147, 27);
			txtUserName.setName("User Name");
			txtUserName.addKeyListener(this);
			txtUserName.setFont(new Font("Tahoma", Font.PLAIN, 11));
			pnlLocation.add(txtUserName);

			lblPassword = new JLabel("Password :");
			lblPassword.setHorizontalAlignment(SwingConstants.TRAILING);
			lblPassword.setBounds(10, 51, 110, 26);
			lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 11));
			pnlLocation.add(lblPassword);

			cboRole = new JComboBox();
			cboRole.setBounds(125, 79, 123, 27);
			cboRole.setFont(new Font("Tahoma", Font.PLAIN, 11));
			cboRole.addItemListener(this);
			cboRole.setName("Role");
			pnlLocation.add(cboRole);

			btnNewButton = new JButton("New button");
			btnNewButton.setBounds(249, 79, 23, 27);
			pnlLocation.add(btnNewButton);

			lblRole = new JLabel("Role :");
			lblRole.setHorizontalAlignment(SwingConstants.TRAILING);
			lblRole.setBounds(10, 79, 110, 26);
			lblRole.setFont(new Font("Tahoma", Font.PLAIN, 11));
			pnlLocation.add(lblRole);

			txtPassword = new JPasswordField();
			txtPassword.setBounds(125, 51, 147, 27);
			txtPassword.setFont(new Font("Tahoma", Font.PLAIN, 11));
			txtPassword.setName("Password");
			pnlLocation.add(txtPassword);

			pnlOption = new JPanel();
			pnlOption.setBounds(0, 209, 362, 30);
			pnlUser.add(pnlOption);
			pnlOption.setLayout(null);
			
						btnAdd = new JButton("Add");
						btnAdd.setBounds(115, 0, 98, 28);
						pnlOption.add(btnAdd);
						btnAdd.setEnabled(false);
						btnAdd.setFont(new Font("Tahoma", Font.PLAIN, 10));
						btnAdd.addActionListener(this);

			btnCancel = new JButton("Cancel");
			btnCancel.setBounds(220, 0, 98, 28);
			pnlOption.add(btnCancel);
			btnCancel.setFont(new Font("Tahoma", Font.PLAIN, 10));
			btnCancel.addActionListener(this);
			group.add(cboRole, ValidatorUtils
 					.merge(StringValidators.REQUIRE_NON_EMPTY_STRING));
			group.add(txtUserName, ValidatorUtils
					.merge(StringValidators.REQUIRE_NON_EMPTY_STRING));

			setSize(384, 319);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void keyPressed(KeyEvent arg0) {
 
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
 
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
	 
	}

	@Override
	public void itemStateChanged(ItemEvent arg0) {
 
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
 
	}

	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				Register dialog = new Register(null, true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}
}
